﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SISTEMA_ALPROVIDE.Model;
using SISTEMA_ALPROVIDE.Bean;
using MySql.Data.MySqlClient;
using System.Windows.Forms;

namespace SISTEMA_ALPROVIDE.DAO
{
    public class DAOCliente
    {
        private ConexionBD conn = new ConexionBD();

        public List<Cliente> ObtenerCliente(string dni,string ApellidoPaterno)
        {
            List<Cliente> listaCliente = new List<Cliente>();
            try
            {
                conn.Open();
                MySqlCommand comm = new MySqlCommand();
                comm.Connection = conn.getConexion;
                comm.CommandText = "SELECT * FROM persona where ESTADO=1";

                if (!String.IsNullOrEmpty(dni))
                {
                    comm.CommandText += " AND DNI = " + dni + "";
                }

                if (!String.IsNullOrEmpty(ApellidoPaterno))
                {
                    comm.CommandText += " AND APELLIDOP = " + ApellidoPaterno + "";
                }

                MySqlDataReader myReader = comm.ExecuteReader();

                while (myReader.Read())
                {
                    Cliente cliente = new Cliente();
                    cliente.DNI = Convert.ToInt32(myReader["DNI"]);
                    cliente.Nombre = Convert.ToString(myReader["NOMBRE"]);
                    cliente.ApellidoPaterno = Convert.ToString(myReader["APELLIDOP"]);
                    cliente.ApellidoMaterno = Convert.ToString(myReader["APELLIDOM"]);

                    listaCliente.Add(cliente);
                }
                return listaCliente;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                throw e;
            }
            finally
            {
                conn.Close();
            }

        }

    }
}
